1
|
|
|
var Subject = require('./Subject'), |
2
|
|
|
ResourceReference = require('./ResourceReference'), |
3
|
|
|
TextValue = require('./TextValue'), |
4
|
|
|
GDate = require('./Date'), |
5
|
|
|
utils = require('./utils'); |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* A description of a place |
9
|
|
|
* |
10
|
|
|
* @constructor |
11
|
|
|
* @param {Object} [json] |
|
|
|
|
12
|
|
|
*/ |
13
|
|
|
var PlaceDescription = function(json){ |
14
|
|
|
|
15
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
16
|
|
|
if(!(this instanceof PlaceDescription)){ |
17
|
|
|
return new PlaceDescription(json); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
21
|
|
|
if(PlaceDescription.isInstance(json)){ |
22
|
|
|
return json; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
Subject.call(this, json); |
26
|
|
|
|
27
|
|
|
if(json){ |
|
|
|
|
28
|
|
|
this.setType(json.type); |
29
|
|
|
this.setNames(json.names); |
30
|
|
|
this.setPlace(json.place); |
31
|
|
|
this.setJurisdiction(json.jurisdiction); |
32
|
|
|
this.setTemporalDescription(json.temporalDescription); |
33
|
|
|
this.setSpatialDescription(json.spatialDescription); |
34
|
|
|
this.setLatitude(json.latitude); |
35
|
|
|
this.setLongitude(json.longitude); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
}; |
38
|
|
|
|
39
|
|
|
PlaceDescription.prototype = Object.create(Subject.prototype); |
40
|
|
|
|
41
|
|
|
PlaceDescription._gedxClass = PlaceDescription.prototype._gedxClass = 'GedcomX.PlaceDescription'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Check whether the given object is an instance of this class. |
45
|
|
|
* |
46
|
|
|
* @param {Object} obj |
47
|
|
|
* @returns {Boolean} |
48
|
|
|
*/ |
49
|
|
|
PlaceDescription.isInstance = function(obj){ |
50
|
|
|
return utils.isInstance(obj, this._gedxClass); |
51
|
|
|
}; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the type |
55
|
|
|
* |
56
|
|
|
* @returns {String} |
57
|
|
|
*/ |
58
|
|
|
PlaceDescription.prototype.getType = function(){ |
59
|
|
|
return this.type; |
60
|
|
|
}; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set the type |
64
|
|
|
* |
65
|
|
|
* @param {String} type |
66
|
|
|
* @returns {PlaceDescription} |
67
|
|
|
*/ |
68
|
|
|
PlaceDescription.prototype.setType = function(type){ |
69
|
|
|
this.type = type; |
70
|
|
|
return this; |
71
|
|
|
}; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the names |
75
|
|
|
* |
76
|
|
|
* @returns {TextValue[]} |
77
|
|
|
*/ |
78
|
|
|
PlaceDescription.prototype.getNames = function(){ |
79
|
|
|
return this.names || []; |
80
|
|
|
}; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set the names |
84
|
|
|
* |
85
|
|
|
* @param {TextValue[]|Object[]} names |
86
|
|
|
* @returns {PlaceDescription} |
87
|
|
|
*/ |
88
|
|
|
PlaceDescription.prototype.setNames = function(names){ |
89
|
|
|
return this._setArray(names, 'names', 'addName'); |
90
|
|
|
}; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Add the name |
94
|
|
|
* |
95
|
|
|
* @param {TextValue|Object} name |
96
|
|
|
* @returns {PlaceDescription} |
97
|
|
|
*/ |
98
|
|
|
PlaceDescription.prototype.addName = function(name){ |
99
|
|
|
return this._arrayPush(name, 'names', TextValue); |
100
|
|
|
}; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the place |
104
|
|
|
* |
105
|
|
|
* @returns {ResourceReference} |
106
|
|
|
*/ |
107
|
|
|
PlaceDescription.prototype.getPlace = function(){ |
108
|
|
|
return this.place; |
109
|
|
|
}; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set the place |
113
|
|
|
* |
114
|
|
|
* @param {ResourceReference} place |
115
|
|
|
* @returns {PlaceDescription} |
116
|
|
|
*/ |
117
|
|
|
PlaceDescription.prototype.setPlace = function(place){ |
118
|
|
|
if(place){ |
119
|
|
|
this.place = ResourceReference(place); |
120
|
|
|
} |
121
|
|
|
return this; |
122
|
|
|
}; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the jurisdiction |
126
|
|
|
* |
127
|
|
|
* @returns {ResourceReference} |
128
|
|
|
*/ |
129
|
|
|
PlaceDescription.prototype.getJurisdiction = function(){ |
130
|
|
|
return this.jurisdiction; |
131
|
|
|
}; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Set the jurisdiction |
135
|
|
|
* |
136
|
|
|
* @param {ResourceReference} jurisdiction |
137
|
|
|
* @returns {PlaceDescription} |
138
|
|
|
*/ |
139
|
|
|
PlaceDescription.prototype.setJurisdiction = function(jurisdiction){ |
140
|
|
|
if(jurisdiction){ |
141
|
|
|
this.jurisdiction = ResourceReference(jurisdiction); |
142
|
|
|
} |
143
|
|
|
return this; |
144
|
|
|
}; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get the latitude |
148
|
|
|
* |
149
|
|
|
* @returns {Number} |
150
|
|
|
*/ |
151
|
|
|
PlaceDescription.prototype.getLatitude = function(){ |
152
|
|
|
return this.latitude; |
153
|
|
|
}; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Set the latutide |
157
|
|
|
* |
158
|
|
|
* @param {Number} latitude |
159
|
|
|
* @returns {PlaceDescription} |
160
|
|
|
*/ |
161
|
|
|
PlaceDescription.prototype.setLatitude = function(latitude){ |
162
|
|
|
this.latitude = latitude; |
163
|
|
|
return this; |
164
|
|
|
}; |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Get the longitude |
168
|
|
|
* |
169
|
|
|
* @returns {Number} |
170
|
|
|
*/ |
171
|
|
|
PlaceDescription.prototype.getLongitude = function(){ |
172
|
|
|
return this.longitude; |
173
|
|
|
}; |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Set the latutide |
177
|
|
|
* |
178
|
|
|
* @param {Number} longitude |
179
|
|
|
* @returns {PlaceDescription} |
180
|
|
|
*/ |
181
|
|
|
PlaceDescription.prototype.setLongitude = function(longitude){ |
182
|
|
|
this.longitude = longitude; |
183
|
|
|
return this; |
184
|
|
|
}; |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Get the temporal description |
188
|
|
|
* |
189
|
|
|
* @returns {Date} |
190
|
|
|
*/ |
191
|
|
|
PlaceDescription.prototype.getTemporalDescription = function(){ |
192
|
|
|
return this.temporalDescription; |
193
|
|
|
}; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Set the temporal description |
197
|
|
|
* |
198
|
|
|
* @param {Date} date |
199
|
|
|
* @returns {PlaceDescription} |
200
|
|
|
*/ |
201
|
|
|
PlaceDescription.prototype.setTemporalDescription = function(date){ |
202
|
|
|
if(date){ |
203
|
|
|
this.temporalDescription = GDate(date); |
204
|
|
|
} |
205
|
|
|
return this; |
206
|
|
|
}; |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get the spatial description |
210
|
|
|
* |
211
|
|
|
* @returns {ResourceReference} |
212
|
|
|
*/ |
213
|
|
|
PlaceDescription.prototype.getSpatialDescription = function(){ |
214
|
|
|
return this.spatialDescription; |
215
|
|
|
}; |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Set the spatial description |
219
|
|
|
* |
220
|
|
|
* @param {ResourceReference} spatial |
221
|
|
|
* @returns {PlaceDescription} |
222
|
|
|
*/ |
223
|
|
|
PlaceDescription.prototype.setSpatialDescription = function(spatial){ |
224
|
|
|
if(spatial){ |
225
|
|
|
this.spatialDescription = ResourceReference(spatial); |
226
|
|
|
} |
227
|
|
|
return this; |
228
|
|
|
}; |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Export the object as JSON |
232
|
|
|
* |
233
|
|
|
* @return {Object} JSON object |
234
|
|
|
*/ |
235
|
|
|
PlaceDescription.prototype.toJSON = function(){ |
236
|
|
|
return this._toJSON(Subject, [ |
237
|
|
|
'type', |
238
|
|
|
'names', |
239
|
|
|
'place', |
240
|
|
|
'jurisdiction', |
241
|
|
|
'latitude', |
242
|
|
|
'longitude', |
243
|
|
|
'temporalDescription', |
244
|
|
|
'spatialDescription' |
245
|
|
|
]); |
246
|
|
|
}; |
247
|
|
|
|
248
|
|
|
module.exports = PlaceDescription; |